#include ("/_includes/_layout.html")
#define css()
<link rel="stylesheet" type="text/css" href="#(webctx)/resources/css/product.css"/>
<style type="text/css">
.Item ul {  
    list-style: none;  
    line-height: 40px;
}  
.Item li {  
    display: block;  
    float: left;  
}  
</style>
#end
#@layout("商品规格", "wxmall,点步科技", "Wxmall社区","wxmall") 
#define content()
<div class="wrapper wrapper-content">
	   <div id="tableList" class="ibox-content">
			<div class="panel-body">
				<select id="a_status_sel" class="control-inline">
					<option value="">全部</option>
					<option value="1" selected="selected">启用</option>
					<option value="0">已删除</option>
				</select>
				<button onclick="addSpecification();" class="btn btn-success">添加规格</button>
			</div>
			<table class="table table-striped table-bordered bootstrap-datatable datatable" id="mainTable" border="0">
				<thead>
					<tr>
						<th><input type="checkbox" id="all" title="全选/反选" style="margin-right: 4px; vertical-align: middle;"/></th>
						<th><span style="vertical-align: middle;">&nbsp;&nbsp;规格</span></th>
						<th>规格值</th>
						<th>状态</th>
						<th>创建时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody class="specificationLotGrid">
				</tbody>
			</table>
			<div id="specificationToolsbar" class="panel-body">
				<div id="pager" class="jqpager" style="margin-bottom: 1px;float: right;"></div>
			</div>
		</div>
</div>
<!-- 模板开始 -->
<script type="text/template" id="specification_table_tr_tpl">
		<tr class="package">
			<td><input type="checkbox" class="commchk" id="checkbox_{id}" style="margin-right: 4px; vertical-align: middle;"/></td>
		    <td>{name}</td>
		    <td width="500px"><ul class="Item specificationValueSelect_{id}"></ul></td>
			<td>{active}</td>			
			<td>{created}</td>
			<td>&nbsp;<a id="edit#{id}" href="javascript:void(0)">编辑</a></td>
		</tr>
</script>

<script type="text/template" id="specificationValues">
	<li>{name},&nbsp;</li>
</script>

<script type="text/template" id="table_noresult_tr_tpl">
	<tr class="package">
			<td class="center" colspan="6">
				没有结果集，现在去创建吧，
				<a href="#(webctx)/specification/add" style="text-decoration: underline;">去创建</a>
			</td>
		</tr>
</script>
#end
<script type="text/javascript">
function addSpecification(){
	location.href=obz.ctx + "/specification/add";
}
var params = {};
params.active = $("#a_status_sel").val();
var table = new obz.TableView("pager", obz.ctx + "/specification/list", params, function(resp){
	$(".specificationLotGrid").empty();
	if(resp && resp.list && resp.list.length>0){
		var dataList = resp.list;
		if(dataList.length>0){
			for(var i=0;i<dataList.length;i++){
				var _row = dataList[i];
				if(_row.active == 1){
					_row.active = "启用";
				}
				if(_row.active == 0){
					_row.active = "<font color='red'>删除</font>";
				}
				var trHtml = obz.dataTemplate4obj($("#specification_table_tr_tpl").html(), _row);
				$(".specificationLotGrid").append(trHtml);
				for(var j=0;j<_row.specificationValues.length;j++){
					var s_row=_row.specificationValues[j];	 
					var liHtml = obz.dataTemplate4obj($("#specificationValues").html(),s_row);	
					$(".specificationValueSelect_"+_row.id).append(liHtml);
				}
			}
			TBatch.checkCheckbox();
			TBatch.initCheckboxClick();
			TBatch.initOptEvent(ActivityTableOpt.init());
		}else{
			$(".specificationLotGrid").append($("#table_noresult_tr_tpl").html());
		}
	}else{
		$(".specificationLotGrid").append($("#table_noresult_tr_tpl").html());
	}
});
table.init();

var ActivityTableOpt = {
	edit : function(param){
		var id = param[1];
		location.href = obz.ctx + "/specification/edit/"+id;
	}, 
	init : function(){
		var optArray = new Array();
		optArray.push(this.edit);
		return optArray;
	}
}		

$("#a_status_sel").change(function(){
	params.active = $("#a_status_sel").val();
	table.init();
});
//=============================表格操作事件结束=============================================
</script>